package com.shortchina.init;

import com.shortchina.common.CommonCache;
import com.shortchina.common.CommonConfig;
import com.shortchina.config.TshortSevice;
import com.shortchina.config.redis.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author fc
 * @version 1.0
 * @data 2024/12/24 12:17 下午
 **/
@Component
public class BootInit implements InitializingBean {
    private final Logger logger = LoggerFactory.getLogger(BootInit.class);
    @Resource
    private RedisService redisService;

    @Resource
    private TshortSevice tshortSevice ;

    //定义log颜色
    private String logcolor = "\033[35m";
    private String logcolorend = "\033[0m";


    @Override
    public void afterPropertiesSet() throws Exception {
        redisService.del(CommonCache.DEFAULT_AK_SK);
        logger.info(logcolor +"YML初始化YML配置的AK和SK"+ logcolorend);
        List<TshortSevice.Secret> secretList =  tshortSevice.getSecret();
        for (TshortSevice.Secret secret : secretList) {
            redisService.hashPut(CommonCache.DEFAULT_AK_SK, secret.getAK(), secret.getSK());
        }
        CommonConfig.DEFAULT_VALID_TIME= tshortSevice.getExpire();
        logger.info(logcolor +"YML初始化过期时间为:{}秒"+logcolorend,CommonConfig.DEFAULT_VALID_TIME);
    }
}
